﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;
namespace PESSReports
{
    public partial class ArchiveScoresReportForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.ReportViewer1.AsyncRendering = false;//important

                ReportViewer1.LocalReport.DataSources.Clear();

                //  2. Get Connection String from Web.Config
                SqlDbProxy.ConnectionString = System.Configuration.ConfigurationManager.
                ConnectionStrings["PESSReportingConnectionString"].ConnectionString;

                //  3. Create DataSets (In my case I use 2 DataSets,
                //     you can use one or more)
                //DataSet dsHeader = new DataSet();
                //DataSet dsDetail = new DataSet();
                DataSet ds;// = new DataSet();


                //  4. Select the DataSource to both DataSets
                // (In my case both SQL Stored Procedures
                //   use the same Sql parameter)

                //SqlParameter sqlParm = new SqlParameter("@intNr",
                //                                        lineNr.ToString());
                //dsHeader = SqlHelper.ExecuteDataset(sqlCon,
                //           CommandType.StoredProcedure,
                //           "stp_S_LoadHeaderData", sqlParm);
                //dsDetail = SqlHelper.ExecuteDataset(sqlCon,
                //           CommandType.StoredProcedure,
                //           "stp_S_LoadDetailData", sqlParm);
                SqlDbProxy db = new SqlDbProxy("GetScores");
                db.AddParameter("@SubjectID", Convert.ToInt32(Request["subjectID"]));//"9");
                ds = db.GetDataSet();

                //  5. The next lines mean that you will fill the datasets
                //     with the data retrieved from the stored procedures.
                //     I had on my SQL database, giving a input parameter
                //     sqlParam as you can see before
                //     Create datasource to the report - this way you associate
                //     these local datasets to your project datasets,
                //     with the correctly loaded data
                //     Notice that DS1_stp_s_LoadHeaderData and
                //     DS1_stp_s_LoadDetailData are my Report DataSets,
                //     so you can Map the local Datasets to the report datasets

                //ReportDataSource reportDSHeader =
                //  new ReportDataSource("DS1_stp_s_LoadHeaderData",
                //                       dsHeader.Tables[0]);
                //ReportDataSource reportDSDetail =
                //  new ReportDataSource("DS1_stp_s_LoadDetailData",
                //                       dsDetail.Tables[0]);
                ReportDataSource reportDS = new ReportDataSource("DataSet1", ds.Tables[0]);

                //  6. Add these DataSources to your ReportViewer, et voilá!

                //ReportViewer1.LocalReport.DataSources.Add(reportDSHeader);
                //ReportViewer1.LocalReport.DataSources.Add(reportDSDetail);
                ReportViewer1.LocalReport.DataSources.Add(reportDS);

                ReportViewer1.LocalReport.Refresh();
                ReportViewer1.Visible = true;
            }
  
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            
        }
    }
}